/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.06.10
 *Time:19:06
 */

import Demo2.Stu;

class MyData{

    //成员变量
    int year = 2024;
    int month = 5;
    int day = 20;

    //成员方法
    void print(int year,int month,int day){

        //print方法是myData引用调用的，this替换的就是myData这个引用
        //this.year表示myData指向的类中的year，即2024
        //this.month表示myData指向的类中的month,即5
        //this.day表示myData指向的类中的day，即20
        System.out.println("日期：" + this.year + " " + this.month + " " + this.day);
    }
}
//声明一个学生类
class Student{

    //成员变量
    String name;//名字
    int age;
    static String Class = "1班";//静态成员变量


    //构造方法:public + 类名 构成
    public Student(String name, int age){
        //this替换引用:指向成员变量
        this.name = name;//参数的name
        this.age = age;//参数的age
    }

    //重写toString方法
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class Test{
    //成员
    int a;
    int b;
    static char[] chars;
    //构造方法
    public Test(){
        System.out.println("构造方法执行了......");
    }
    //实例化代码块
    {
        this.a = 20;
        this.b = 30;
        System.out.println("构造代码块执行了.......");
    }
    //静态代码块
    static{
        char[] chars1 = {'H','e','l','l','o'};
        System.out.println("静态代码块执行了......");
    }
    void show(){
        System.out.println("a = " + a + " "+ "b = " + b);
    }
    public static void main(String[] args) {

        Test test = new Test();
        System.out.println("=================");
        Test test1 = new Test();

    }
}


public class Main{

    public static void main(String[] args) {

        Test test = new Test();
        test.show();
    }

    public static void main4(String[] args) {

        int x;
        //执行{}普通代码块
        {
            x = 10;
            System.out.println("普通代码块被执行了，x = " + x);
        }
    }


    public static void main3(String[] args) {

        //实例化对象
        Student student1 = new Student("笑笑",20);
        Student student2 = new Student("王王",12);

        //输出
        System.out.println(student1);
        System.out.println(student2);

    }

    public static void main1(String[] args) {

        //实例化对象
        MyData myData = new MyData();
        //访问类中的方法:引用 + 成员方法名
        myData.print(2024,5,10);
    }

}
